/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.account.Key.AccountBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.MailboxManager;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class DeleteMailbox
/*    */   extends AdminDocumentHandler
/*    */ {
/* 41 */   private static final String[] TARGET_ACCOUNT_PATH = { "mbox", "id" };
/* 42 */   protected String[] getProxiedAccountPath() { return TARGET_ACCOUNT_PATH; }
/*    */   
/*    */ 
/*    */ 
/*    */   public boolean domainAuthSufficient(Map<String, Object> context)
/*    */   {
/* 48 */     return true;
/*    */   }
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context) throws ServiceException {
/* 52 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*    */     
/* 54 */     Element mreq = request.getElement("mbox");
/* 55 */     String accountId = mreq.getAttribute("id");
/*    */     
/* 57 */     Account account = Provisioning.getInstance().get(Key.AccountBy.id, accountId, zsc.getAuthToken());
/* 58 */     if (account == null)
/*    */     {
/* 60 */       if (isDomainAdminOnly(zsc)) {
/* 61 */         throw ServiceException.PERM_DENIED("account doesn't exist, unable to determine authorization");
/*    */       }
/*    */       
/*    */ 
/*    */ 
/*    */ 
/* 67 */       checkRight(zsc, context, null, Rights.Admin.R_deleteAccount);
/*    */       
/* 69 */       ZimbraLog.account.warn("DeleteMailbox: account doesn't exist: " + accountId + " (still deleting mailbox)");
/*    */     }
/*    */     else {
/* 72 */       checkAccountRight(zsc, account, Rights.Admin.R_deleteAccount);
/*    */     }
/*    */     
/* 75 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(accountId, false);
/* 76 */     int mailboxId = -1;
/* 77 */     if (mbox != null) {
/* 78 */       mailboxId = mbox.getId();
/* 79 */       mbox.deleteMailbox();
/*    */     }
/*    */     
/* 82 */     String idString = mbox == null ? "<no mailbox for account " + accountId + ">" : Integer.toString(mailboxId);
/*    */     
/* 84 */     ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "DeleteMailbox", "id", idString }));
/*    */     
/*    */ 
/* 87 */     Element response = zsc.createElement(AdminConstants.DELETE_MAILBOX_RESPONSE);
/* 88 */     if (mbox != null) {
/* 89 */       response.addElement("mbox").addAttribute("mbxid", mailboxId);
/*    */     }
/* 91 */     return response;
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 96 */     relatedRights.add(Rights.Admin.R_deleteAccount);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/DeleteMailbox.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */